<?php

/**
 * Framework_Presenter_Ajax
 *
 * @author Application Support Group
 * @copyright University of Georgia
 * @package BAMF
 * @filesource
 */

require_once('XML/Serializer.php');

/**
 * Framework_Presenter_Ajax
 * *
 * @author Application Support Group
 * @package BAMF
 */
class Framework_Presenter_Ajax extends Framework_Presenter_Common
{

    /**
     * __construct
     *
     * @author Application Support Group
     * @access public
     * @param mixed $module Instance of Framework_Module
     * @return void
     */
    public function __construct(Framework_Module $module)
    {
        parent::__construct($module);
    }

    /**
     * display
     *
     * @author Application Support Group
     * @return void
     * @link http://pear.php.net/package/XML_Serializer
     */
    public function display()
    {
        $xml = new XML_Serializer() ;
        $returnData = array() ;
		$params = array() ;

		if ( isset( $_GET["returnFunction"] )) {
			$params["_returnFunction"] = $_GET["returnFunction"] ;
		}

		foreach ( $this->module->getData() as $var => $val ) {
			if ($var{0} == "_") {
				$params[ $var ] = $val ;
			} else {
				$returnData[ $var ] = $val ;
			}
		
			$xml->serialize( array( "params" => $params, "data" => $returnData )) ;		
		}

        header("Content-Type: text/xml");
        echo '<?xml version="1.0" encoding="UTF-8" ?>'."\n";
        echo $xml->getSerializedData();
    }

    public function __destruct()
    {
        parent::__destruct();
    }
}

?>
